package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try(
            Connection conn = DBUtil1.getTeduConnection();
        ){
            // 创建statement对象
            Statement statement = conn.createStatement();

            // 查看1年级1班的学生信息
            String sql = "SELECT COUNT(*) count " +
                    "FROM class c " +
                    "JOIN student s ON c.id = s.class_id " +
                    "WHERE c.name = '1年级1班'";
            System.out.println(sql);
            ResultSet rs = statement.executeQuery(sql);
            // 遍历结果集
            while(rs.next()){
                int count = rs.getInt("count");
                System.out.println("1年级1班共有多少人：" + count);
            }



        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
